package com.niuwa.p2p.action.loan;

import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.niuwa.p2p.action.JsonAction;
import com.niuwa.p2p.core.mvc.entity.PageBean;
import com.niuwa.p2p.service.loan.ILoanService;
import com.niuwa.p2p.vo.loan.LoanVo;

/**
 * 放款管理action
 * 
 * @author houdianbo
 * @Date 2015-04-24
 */
@Controller
public class LoanAction extends JsonAction {
	private static final long serialVersionUID = 3412842078597429513L;
	private static Logger logger = Logger.getLogger(LoanAction.class);
	@Autowired
	private ILoanService loanService;

	/**
	 * 跳转至放款列表页面
	 * 
	 * @return
	 */
	@Action(value = "gotoLoanManage", results = { @Result(location = "loanManage.jsp", name = SUCCESS) })
	public String gotoLoanManage() {
		logger.info("gotoLoanManage action execute success");
		return SUCCESS;
	}

	/**
	 * 放款列表
	 * 
	 * @return
	 * @throws Exception
	 */
	@Action(value = "searchLoanList")
	public String searchLoanList() throws Exception {
		setObjectReSult(queryPagination());
		logger.info("searchLoanList action execute success");
		return NONE;
	}

	/**
	 * 分页查询
	 * 
	 * @return Pagination<LoanVo>
	 */
	private PageBean<LoanVo> queryPagination() {
		// 获取查询参数
		Map<String, Object> paramMap = getParamMap();
		logger.debug(paramMap);
		// 执行查询操作
		PageBean<LoanVo> pagination = loanService.selectLoanByParam(paramMap);
		return pagination;
	}

	public void setLoanService(ILoanService loanService) {
		this.loanService = loanService;
	}

}
